define(["translate"],function(){
	function translate(original, translate, text)
	{
		var textarea=document.getElementById("text");
		var spinner=document.getElementById("spinner");
		if(!navigator.onLine)
			alert("Sorry, but you are offline");
		if(text==null || text==undefined || text=="")
			alert("Put something on the text control!");
	
		var xhr=new XMLHttpRequest();
		var url="http://apy.projectjj.com/translate?q="+encodeURIComponent(text)+"&langpair="+encodeURIComponent(original + "|" + translate);
		//console.log("Opening "+url);
		xhr.open(url,"GET");
		xhr.addEventListener("load",function(){
			var json=JSON.parse(xhr.responseText);
			textarea.value=json.responseData.translatedText;
			spinner.style.visibility="hidden";
		});
		xhr.send();
	}
	return {translate:translate};
})
